<template>
	<view class="beijingse">
		<view class="mainpadding" style="padding-bottom: 0;">
			<view class="flexbetween ssbox" style="background-color: #fff;">
				<view class="flexleft">
					<u-icon name="search" color="#999" size="20"></u-icon>
					<input type="text" placeholder="请输入搜索内容" class="hei_text main_size bold" v-model="keywords"
						confirm-type="search" @confirm="init()">
				</view>
				<view class="rightss" @click="init()">搜索</view>
			</view>
		</view>
		<view class="mainpadding2">
			<goodslist :list="list.data"></goodslist>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				type: "",
				text: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				keywords: "",
				category_id:""
			}
		},
		onLoad(options) {
			this.type = options.id
			let text = ""
			if (this.type == 1) {
				this.text = "会员大礼包"
			} else if (this.type == 3) {
				this.text = "积分商品"
			}else if (this.type == 4) {
				this.text = "非常2+1"
			} else{
				this.text = "商品列表"
			}
			if(options.keywords){
				this.keywords = options.keywords
			}
			if(options.category_id){
				this.category_id = options.category_id
			}
			uni.setNavigationBarTitle({
				title: this.text
			});
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/goodscl/goodsList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					type:this.type,
					category_id:this.category_id,
					keyword:this.keywords
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>